﻿<!--#include file="../inc/easp/easp.asp"-->
<!--#include file="../inc/conn1.asp"-->
<!--#include file="../inc/checklogin.asp"-->
<!--#include file="../inc/easyide.asp"-->
<% CheckLogin("../index.asp") %>
<%
	If Session("Authority")<>"0" Then
		Response.Write "<script type=""text/javascript"">top.location.href='../main.asp';</script>"
	end if				
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  <%
    
		  Easp.w "Edit Country"
		
  %>
</title>
<link rel="stylesheet" type="text/css" href="../css/theme.css" />
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<script type="text/javascript">
	var StyleFile = "theme" + document.cookie.charAt(6) + ".css";
	document.writeln('<link rel="stylesheet" type="text/css" href="../css/' + StyleFile + '">');
	
	function chkv(obj)
    { 
        var txtCountryName=document.getElementById("txtCountryName");
        var yid=document.getElementById("yid");
        var holidays=document.getElementById("txtHolidaysName");
        
        var Board1=document.getElementById("txtWellBoard1");
         var Board2=document.getElementById("txtWellBoard2");
         var Board3=document.getElementById("txtWellBoard3");
         var Url1=document.getElementById("txtWellBoardUrl1");
         var Url2=document.getElementById("txtWellBoardUrl2");
         var Url3=document.getElementById("txtWellBoardUrl3");

        
       // alert("EditCountry.asp?action=custom&selectedIndex="+obj.options[obj.selectedIndex].value+"&CountryName="+txtCountryName.value+"&yid="+yid.value);
        top.location.href="EditCountry.asp?action=custom&selectedIndex="+obj.options[obj.selectedIndex].value+"&CountryName="+txtCountryName.value+"&yid="+yid.value+"&holidays="+holidays.value+"&Board1="+Board1.value+"&Board2="+Board2.value+"&Board3="+Board3.value+"&Url1="+Url1.value+"&Url2="+Url2.value+"&Url3="+Url3.value;
        
        //alert("AddCountry.asp?action=custom&selectedIndex="+obj.selectedIndex+"&CountryName="+txtCountryName.value);
    } 
    
    function Add()
    { 
        var txtCountryName=document.getElementById("txtCountryName");
        var obj=document.getElementById("group");
        var holidays=document.getElementById("txtHolidaysName");
        
        var yid=document.getElementById("yid");
        
         var Board1=document.getElementById("txtWellBoard1");
         var Board2=document.getElementById("txtWellBoard2");
         var Board3=document.getElementById("txtWellBoard3");
         var Url1=document.getElementById("txtWellBoardUrl1");
         var Url2=document.getElementById("txtWellBoardUrl2");
         var Url3=document.getElementById("txtWellBoardUrl3");

        if (txtCountryName.value == "")
	    {		
		    obj["txtCountryName"].focus();
		    return false;
	    }
	    
	     if (txtHolidaysName.value == "")
	    {		
		    obj["txtHolidaysName"].focus();
		    return false;
	    }
        
        
        top.location.href='EditCountry.asp?action=submit&selectedIndex='+obj.options[obj.selectedIndex].value+"&CountryName="+txtCountryName.value+"&yid="+yid.value+"&holidays="+holidays.value+"&Board1="+Board1.value+"&Board2="+Board2.value+"&Board3="+Board3.value+"&Url1="+escape(Url1.value)+"&Url2="+escape(Url2.value)+"&Url3="+escape(Url3.value);
    } 
    
    function test_int(a)
     {   
        var myReg = /^[0-9]*[0-9]$/;  
         
        if(myReg.test(a))   
        {
            return true;
        }    
        return false;   
    }   

    
    function Edit()
    { 
    
        var txtCountryName=document.getElementById("txtCountryName");
        
        var obj=document.getElementById("group");
        
        var yid=document.getElementById("yid");

        var holidays=document.getElementById("txtHolidaysName");
        
        var Board1=document.getElementById("txtWellBoard1");
         var Board2=document.getElementById("txtWellBoard2");
         var Board3=document.getElementById("txtWellBoard3");
         var Url1=document.getElementById("txtWellBoardUrl1");
         var Url2=document.getElementById("txtWellBoardUrl2");
         var Url3=document.getElementById("txtWellBoardUrl3");
         
//         alert(Board1.value);
//         alert(Board2.value);
//         alert(Board3.value);
//         alert(Url1.value);
//         alert("txtWellBoardUrl2"+Url2.value);
//         alert(Url3.value);
        
        if (txtCountryName.value == "")
	    {		
		    obj["txtCountryName"].focus();
		    
		    return false;
	    }
	    
	    if (holidays.value == "")
	    {		
		    obj["txtHolidaysName"].focus();
		    return false;
	    }
	    
	    
	    if(!test_int(holidays.value))
	    {
	        alert("Please input number");
	        return false;
	    }
        
         var h=parseInt(holidays.value); 
         
         if(h=="NaN")
         {
            alert("Please input number");
	        return false;
         }else
         {
            if(h>20||h<1)
            {
                alert("Holidays Numbers must in 0-20");
	            return false;
            }
         }

 //alert('EditCountry.asp?action=submit&selectedIndex='+obj.options[obj.selectedIndex].value+"&CountryName="+txtCountryName.value+"&yid="+yid.value+"&holidays="+holidays.value+"&Board1="+Board1.value+"&Board2="+Board2.value+"&Board3="+Board3.value+"&Url1="+Url1.value+"&Url2="+Url2.value+"&Url3="+Url3.value);
        top.location.href='EditCountry.asp?action=submit&selectedIndex='+obj.options[obj.selectedIndex].value+"&CountryName="+txtCountryName.value+"&yid="+yid.value+"&holidays="+holidays.value+"&Board1="+Board1.value+"&Board2="+Board2.value+"&Board3="+Board3.value+"&Url1="+escape(Url1.value)+"&Url2="+escape(Url2.value)+"&Url3="+escape(Url3.value);
    } 
    
    
	
</script>
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="css/ie-sucks.css" />
<![endif]-->
</head>
<body>
<div id="container">
	<div id="header">
    <div id="divAccount" style="float:right;">
        <a href="../user/account.asp" style="color:white">Account</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="../inc/logout.asp" style="color:white">Logout</a>
      </div>
		<h2>
	<%
    
		  Easp.w "Add Country"
		
  %>
  </h2>
		<div id="topmenu">
			<ul>
				<li><a href="../main.asp">Home</a></li>
				<li class="current"><a href="#">Country</a></li>
				<li><a href="../holiday/index.asp">Holiday</a></li>
				<li><a href="../Times/index.asp">Times</a></li>
				<li><a href="../wallboard/index.asp">WallBoard</a></li>
				<%
				   If Session("Authority")="0" Then 
				       Response.Write("<li><a href='../user/index.asp'>User</a></li>")
				   End if
				%>
				<li><% If Session("Passed")=true Then %><a href="../inc/logout.asp">Logout</a><% End If %></li>
			</ul>
		</div>
	</div>
	<div id="top-panel">
		<div id="panel">
			<ul>				
				<li><a href="index.asp" class="goback">GoBack</a></li>
			</ul>
		</div>
	</div>
	<div id="wrapper">
		<%

		dim relt

	    dim HolidayFile
	    dim holidaysname
	    dim TimesFile
	    dim yid
	    dim countryname
        dim gid
	    dim groupname
	    
	    dim WellBoard3
	    dim WellBoard2
	    dim WellBoard1
	     dim WellBoardUrl3
	    dim WellBoardUrl2
	    dim WellBoardUrl1
	    dim rscountry
	    
	    dim selectedIndex
	    
	    
	   Function vbsEscape(str)'加密 
                dim i,s,c,a 
                s="" 
                For i=1 to Len(str) 
                    c=Mid(str,i,1) 
                    a=ASCW(c) 
                    If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then 
                        s = s & c 
                    ElseIf InStr("@*_+-./",c)>0 Then 
                        s = s & c 
                    ElseIf a>0 and a<16 Then 
                        s = s & "%0" & Hex(a) 
                    ElseIf a>=16 and a<256 Then 
                        s = s & "%" & Hex(a) 
                    Else 
                        s = s & "%u" & Hex(a) 
                    End If 
                Next 
                vbsEscape = s 
            End Function

             

            Function vbsUnEscape(str)'解密 
                dim i,s,c 
                s="" 
                For i=1 to Len(str) 
                    c=Mid(str,i,1) 
                    If Mid(str,i,2)="%u" and i<=Len(str)-5 Then 
                        If IsNumeric("&H" & Mid(str,i+2,4)) Then 
                            s = s & CHRW(CInt("&H" & Mid(str,i+2,4))) 
                            i = i+5 
                        Else 
                            s = s & c 
                        End If 
                    ElseIf c="%" and i<=Len(str)-2 Then 
                        If IsNumeric("&H" & Mid(str,i+1,2)) Then 
                            s = s & CHRW(CInt("&H" & Mid(str,i+1,2))) 
                            i = i+2 
                        Else 
                            s = s & c 
                        End If 
                    Else 
                        s = s & c 
                    End If 
                Next 
                vbsUnEscape = s 
            End Function



	    'dim a
	    'a =request.QueryString("action")
	    
	    'response.write("<Script language=JavaScript>alert('"&request.QueryString("action")&"');</Script>")
	    
	    if request.QueryString("action")="custom" then
	    

             selectedIndex=request.QueryString("selectedIndex")
            yid=request.QueryString("yid")
            
	        countryname=request.QueryString("CountryName")
	         holidaysname=request.QueryString("holidays")
	         
	         
	     WellBoard3=request.QueryString("Board3")
	     WellBoard2=request.QueryString("Board2")
	     WellBoard1=request.QueryString("Board1")
	     WellBoardUrl3=vbsUnEscape(request.QueryString("Url3"))
	     WellBoardUrl2=vbsUnEscape(request.QueryString("Url2"))
	     WellBoardUrl1=vbsUnEscape(request.QueryString("Url1"))
	     
	     
	     
	    ' set rscountry = Easp.db.GetRecordBySQL("SELECT WallBoardName1, WallBoardName2, WallBoardName3 ,WallBoardValue1,WallBoardValue2,WallBoardValue3  FROM Country  where g_id="&selectedIndex&" and y_id="&yid & " ORDER BY y_id")  
	
	         
	        'response.write("<Script language=JavaScript>alert('selectedIndex:"&request.QueryString("selectedIndex")&"');</Script>")
	        
	        'response.write("<Script language=JavaScript>alert('countryname:"&countryname&"');</Script>")
	        'response.write("<Script language=JavaScript>alert('selectedIndex:"&selectedIndex&"');</Script>")
	    elseif request.QueryString("action")="submit" then
	     
	    
            'page=request.QueryString("page")
            

			     
			     countryname= request.QueryString("CountryName")
			    ' response.write("<Script language=JavaScript>alert('"&countryname&"');</Script>")

			     yid=request.QueryString("yid")
			     
			     selectedIndex=request.QueryString("selectedIndex")
			     
			      holidaysname=request.QueryString("holidays")
			       WellBoard3=request.QueryString("Board3")
	                 WellBoard2=request.QueryString("Board2")
	                 WellBoard1=request.QueryString("Board1")
	                 WellBoardUrl3=vbsUnEscape(request.QueryString("Url3"))
	                 WellBoardUrl2=vbsUnEscape(request.QueryString("Url2"))
	                 WellBoardUrl1=vbsUnEscape(request.QueryString("Url1"))
			     
			      'response.write("<Script language=JavaScript>alert('WellBoardUrl1"&WellBoardUrl1&"');</Script>")
	             ' response.write("<Script language=JavaScript>alert('WellBoardUrl2"&WellBoardUrl2&"');</Script>")
	            ' response.write("<Script language=JavaScript>alert('WellBoardUrl3"&WellBoardUrl3&"');</Script>")
	            '  response.write("<Script language=JavaScript>alert('WellBoard2"&WellBoard1&"');</Script>")
	            '  response.write("<Script language=JavaScript>alert('WellBoard2"&WellBoard2&"');</Script>")
	            '  response.write("<Script language=JavaScript>alert('WellBoard3"&WellBoard3&"');</Script>")
	                  
			     'response.write("<Script language=JavaScript>alert('countryname:"&countryname&"');</Script>")
			     'response.write("<Script language=JavaScript>alert('selectedIndex:"&selectedIndex&"');</Script>")
			     'response.write("<Script language=JavaScript>alert('y_id:"&request.QueryString("yid")&"');</Script>")
			     '插入国家表
		         relt=Easp.db.UpdateRecord("Country","y_id="&yid,Array("g_id:"&selectedIndex,"CountryName:"&countryname,"HolidayNum:"&holidaysname,"WallBoardName3:"&WellBoard3,"WallBoardName2:"&WellBoard2,"WallBoardName1:"&WellBoard1,"WallBoardValue3:"&WellBoardUrl3,"WallBoardValue2:"&WellBoardUrl2,"WallBoardValue1:"&WellBoardUrl1))
		         
		         '查询刚插入的国家号
		         'rscountry=Easp.db.GetRecordBySQL("Select max(y_id) as id  From Country")
		         
		         'if Not Easp.IsN(rscountry) Then
		           ' yid=rscountry("id")
		         'end if
		        ' response.write("<Script language=JavaScript>alert('"&page&"');</Script>")
		         '插入组国家关系表
		         'relt=Easp.db.AddRecord("GroupCountry",Array("GroupID:"&gid,"CountryID:"&yid))
		         
		        Response.Redirect "index.asp"
		        
		   If relt<>0 Then
				 response.write("<Script language=JavaScript>alert('Add  Succeed');</Script>")
			else
				 response.write("<Script language=JavaScript>alert('Add  Failed');</Script>")
			End If  
			
			
			
         elseif request.QueryString("action")="edit" then

			     'response.write("<Script language=JavaScript>alert('"&yid&"');</Script>")
                'response.write("<Script language=JavaScript>alert('"&countryname&"');</Script>")
                'response.write("<Script language=JavaScript>alert('"&selectedIndex&"');</Script>")
			     yid= request.QueryString("yid")
			     
			     countryname=request.QueryString("countryname")
			     
			     selectedIndex=request.QueryString("selectedIndex")
   
                 holidaysname=request.QueryString("holidays")
                 
			     selectedIndex=request.QueryString("selectedIndex")
			     
			     WellBoard3=request.QueryString("Board3")
	             WellBoard2=request.QueryString("Board2")
	             WellBoard1=request.QueryString("Board1")
	              WellBoardUrl3=vbsUnEscape(request.QueryString("Url3"))
	             WellBoardUrl2=vbsUnEscape(request.QueryString("Url2"))
	             WellBoardUrl1=vbsUnEscape(request.QueryString("Url1"))
	            
	             
	            set rscountry = Easp.db.GetRecordBySQL("SELECT WallBoardName1, WallBoardName2, WallBoardName3 ,WallBoardValue1,WallBoardValue2,WallBoardValue3 , y_id FROM Country  where g_id="&selectedIndex&" and y_id="&yid & " ORDER BY y_id")  
	            
	            'response.write("<Script language=JavaScript>alert('WallBoardName1"&rscountry(0)&"');</Script>")
	           ' response.write("<Script language=JavaScript>alert('WallBoardName2"&rscountry(1)&"');</Script>")
	           ' response.write("<Script language=JavaScript>alert('WallBoardName3"&rscountry(2)&"');</Script>")
	           ' response.write("<Script language=JavaScript>alert('WallBoardValue1"&rscountry(3)&"');</Script>")
	            'response.write("<Script language=JavaScript>alert('WallBoardValue2"&rscountry(4)&"');</Script>")
	           ' response.write("<Script language=JavaScript>alert('WallBoardValue3"&rscountry(5)&"');</Script>")
	    
	    end if    
		
		%>
		<div id="content" align="center">	
				<div id="loginbox" align="center" style="margin: 10px 45px; width: 496px;">		
				 <div id="divCountry"  name="divCountry">			
					<form name="form1" id="form4" action="EditCountry.asp?action=custom" method="post">
											  <br/>
					  
					    <table>
					    <tr>
						  <td width="228">
						    Group Name:
						  </td>
						  <td>
					         <% 
                           dim rsgroup,sql 
                           
                           'if request.QueryString("selectedIndex")<> "" then
                             selectedIndex=Trim(request.QueryString("selectedIndex"))
                            
                           'end if
                         
                           
                           set rsgroup= Easp.db.GetRecordBySQL("SELECT Group.ID, Group.GroupName FROM [Group] where 1=1 ") 
    					   
    					   dim count
    					   count=0
    					   dim countgroupid
                           If Not Easp.IsN(rsgroup) Then
                               Easp.wc "<br/>"
                               Easp.wc "<select name='group' id='group'  id='group' style='width:155px;' onchange='chkv(this)'>"
                               While not rsgroup.eof
                               
                                      
                                      If  CStr(selectedIndex) <> CStr("") then
                                            'Response.write("<Script language=JavaScript>alert('selectedIndex:"&selectedIndex&"');</Script>") 
                                            'Response.write("<Script language=JavaScript>alert('rsgroup:"&rsgroup("ID")&"');</Script>")
                                             'Response.write("<Script language=JavaScript>alert('selectedIndex:"&selectedIndex&"');</Script>") 
                                             
                                            If (CStr(rsgroup("ID"))=CStr(selectedIndex)) then 
                                                Easp.wc "<option value='" & rsgroup("ID") & "' selected='selected'>"& rsgroup("GroupName") &"</option>"
                                            Else
                                                'Response.write("dd") 
                                                'Easp.wc "<option value='" & rsgroup("ID") & "' selected='selected'>"& rsgroup("GroupName") &"</option>"
                                                Easp.wc "<option value='" & rsgroup("ID") & "'>"& rsgroup("GroupName") &"</option>"
                                            End if
                                        
                                      Else
                                            if(count<>1) then                                           
                                                countgroupid=rsgroup("ID")
                                                count=count+1
                                            end if                                          
                                      
                                            Easp.wc "<option value='" & rsgroup("ID") & "'>"& rsgroup("GroupName") &"</option>"
                                      End if

						  	          rsgroup.MoveNext()
					           Wend
					           Easp.wc "</select>"
					          
                           End if        
                      %>
						  </td>
						</tr>
					      <tr>
							  <%
								    Easp.w "<td>Country Name:</td>"
									Easp.w "<td><input name='txtCountryName' type='text'  value='"&countryname&"' id='txtCountryName' /></td>"
													      
							  %>						    
						  </tr>						  
                            <tr>
							  <%
								    Easp.w "<td>Holidays Number:</td>"
									Easp.w "<td><input name='txtHolidaysName' type='text'  value='"&holidaysname&"' id='txtHolidaysName' /></td>"
													      
							  %>						    
						  </tr>		
						  
						  <tr>
							  <%
							  If Not Easp.IsN(rscountry) Then
								    Easp.w "<td>Well Board one name:</td>"
									Easp.w "<td><input name='txtWellBoard1' type='text'  value='"&rscountry(0)&"' id='txtWellBoard1' /></td>"
							  else
									Easp.w "<td>Well Board one name:</td>"
									Easp.w "<td><input name='txtWellBoard1' type='text'  value='' id='txtWellBoard1' /></td>"	
							 end if			      
							  %>						    
						  </tr>		
						   <tr>
							  <% If Not Easp.IsN(rscountry) Then
								    Easp.w "<td>Well Board one address:</td>"
									Easp.w "<td><input name='txtWellBoardUrl1' type='text'  value='"&rscountry(3)&"' id='txtWellBoardUrl1' /></td>"
								else 
								Easp.w "<td>Well Board one address:</td>"
									Easp.w "<td><input name='txtWellBoardUrl1' type='text'  value='' id='txtWellBoardUrl1' /></td>"
								 end if						      
							  %>						    
						  </tr>		
						  
						  
						  
						  <tr>
							  <% If Not Easp.IsN(rscountry) Then
								    Easp.w "<td>Well Board two name:</td>"
									Easp.w "<td><input name='txtWellBoard2' type='text'  value='"&rscountry(1)&"' id='txtWellBoard2' /></td>"
									else 
								 Easp.w "<td>Well Board two name:</td>"
									Easp.w "<td><input name='txtWellBoard2' type='text'  value='' id='txtWellBoard2' /></td>"
								 end if					      
							  %>						    
						  </tr>	
						   <tr>
							  <% If Not Easp.IsN(rscountry) Then
								    Easp.w "<td>Well Board two address:</td>"
									Easp.w "<td><input name='txtWellBoardUrl2' type='text'  value='"&rscountry(4)&"' id='txtWellBoardUrl2' /></td>"
								else 
								Easp.w "<td>Well Board one address:</td>"
									Easp.w "<td><input name='txtWellBoardUrl2' type='text'  value='' id='txtWellBoardUrl2' /></td>"
								 end if						      
							  %>						    
						  </tr>		
						  
						  
						  
						  <tr>
							  <% If Not Easp.IsN(rscountry) Then
								    Easp.w "<td>Well Board three name:</td>"
									Easp.w "<td><input name='txtWellBoard3' type='text'  value='"&rscountry(2)&"' id='txtWellBoard3' /></td>"
									else 
								 Easp.w "<td>Well Board three name:</td>"
									Easp.w "<td><input name='txtWellBoard3' type='text'  value='' id='txtWellBoard3' /></td>"
								 end if					      
							  %>						    
						  </tr>	
						  	  <tr>
							  <% If Not Easp.IsN(rscountry) Then
								    Easp.w "<td>Well Board three address:</td>"
									Easp.w "<td><input name='txtWellBoardUrl3' type='text'  value='"&rscountry(5)&"' id='txtWellBoardUrl3' /></td>"
									else 
								Easp.w "<td>Well Board three address:</td>"
							    Easp.w "<td><input name='txtWellBoardUrl3' type='text'  value='' id='txtWellBoardUrl3' /></td>"
								 end if					      
							  %>						    
						  </tr>	

						  <tr>
						      <% 
						       
						            Easp.w "<input type='hidden' name='yid' id='yid' value='"&yid&"' />"
                                    Easp.wc "<td><input name='add' type='button' class='btn' value='Alter' onclick='Edit()'/></td>"
						            Easp.w "<td><input name='reset' type='reset' class='btn' value='Reset' /></td>"
							  %>
						  </tr>
					    </table>					    
					  </div>
					</form>	           
				</div>
	</div>
	<!--#include file="../inc/footer.asp" -->
</div>

</body>
</html>
